<template>
  <Container class="fund-check-info">
    <!-- 基础设置 -->
    <div class="container-header title title-center" slot="header">
      门店基金审核详情
      <Button
        size="large"
        class="fl btn-back"
        icon="ios-arrow-back"
        @click="$router.back()"
      >返回</Button>
    </div>
    <div class="bg-light">
      <div class="container-title">审核状态</div>
      <div class="fleft ml mb">
        <div class="progress-box mr x-big">
          <div class="name tc">{{form.storeName}}</div>
          <p class="big tc">{{form.createDate ? form.createDate.substring(0,11) : ''}}</p>
        </div>
        <div class="progress-box mr x-big" v-if="form.scoreOperateName">
          <div class="name tc">{{form.scoreOperateName}}</div>
          <p class="big tc">{{form.scoreDate ? form.scoreDate.substring(0,11) : ''}}</p>
        </div>
        <div class="progress-box mr x-big" v-if="form.auditOperateName">
          <div class="name tc">{{form.auditOperateName}}</div>
          <p class="big tc">{{form.auditDate ? form.auditDate.substring(0,11) : ''}}</p>
        </div>
        <p class="status font-red ml big">{{form.statusMeaning}}</p>
      </div>
    </div>
    <Tabs v-model="tab" :animated="false" class="need-bottom-border">
      <TabPane label="门店信息" name="tab1" class="scroll">
        <FundCheckInfoItem ref="shopInfo" :form="form" :isCheck="isCheck"/>
      </TabPane>
      <TabPane label="申请内容" name="tab2" class="scroll">
        <fundCheckContentItem :list="contentsList" :isComplete="isComplete" :imageUrls="imageUrls" />
      </TabPane>
    </Tabs>
    <div class="container-footer bg-white" slot="footer" v-if="isCheck">
      <Button class="mr" size="large" @click="onNextOne">下一个</Button>
      <Button class="mr" size="large" @click="onNoPass">审核不通过</Button>
      <Button type="primary" class="mr" size="large" @click="onPass">审核通过</Button>
    </div>
    <NotPassModal ref="notPass" :checkQuery="checkQuery" @complete="toNextChecked"/>
    <Loader :status="status" @refresh="getDetail"></Loader>
  </Container>
</template>
<script>
  import NotPassModal from "./info/NotPassModalItem"
  import FundCheckInfoItem from "./info/FundCheckInfoItem"
  import fundCheckContentItem from "./info/FundCheckContentItem"
  export default {
    name: "",
    components: {
      FundCheckInfoItem,
      fundCheckContentItem,
      NotPassModal
    },
    data() {
      return {
        status: 'loading',
        tab: 'tab1',
        id: this.$route.query.id,
        isCheck: this.$route.query.from == 'check' ? true : false,
        form: {},
        imageUrls: [],
        headImageUrl: '',
        isComplete: false,
        contentsList: [],
        checkQuery: JSON.parse(window.localStorage.getItem('checkQuery')) || {}
      }
    },
    mounted() {
      this.getDetail()
    },
    destroyed() {
      if (window.localStorage.getItem('checkQuery')) window.localStorage.removeItem('checkQuery')
    },
    methods: {
      getDetail() {
        this.status = 'loading'
        this.$ajaxGet(`/assets/fund_month/detail/${this.id}`).then(data => {
          this.status = 'pass'
          this.form = data.storeFundMonthDTO
          this.headImageUrl = data.headImageUrl
          this.imageUrls = data.imageUrls,
          this.isComplete = data.isComplete
          this.form.waitAuditFundNumber = this.form.waitAuditFund
          this.form.address = (data.provinceName ? data.provinceName : '') + (data.cityName ? data.cityName : '') + (data.areaName ? data.areaName : '')
          this.contentsList = this.form.contentsList || []
          if (this.headImageUrl) {
            this.imageUrls.unshift(this.headImageUrl)
          }
        }).catch(() => {
          this.status = 'error'
        })
      },
      onNoPass() {
        let param = {}
        param.auditFundAmount = this.$refs.shopInfo.form.waitAuditFundNumber
        param.auditRemark = this.$refs.shopInfo.form.auditRemark
        this.$refs.notPass.updataForm(this.id, param)
      },
      onNextOne() {
        let param = {
          id: this.id,
          isAudit: true,
          auditFundAmount: this.$refs.shopInfo.form.waitAuditFundNumber,
          auditRemark: this.$refs.shopInfo.form.auditRemark,
          query: {
            ...this.checkQuery
          }
        }
        if (param.auditFundAmount === null || param.auditFundAmount === '' || param.auditFundAmount === undefined) {
          this.$Notice.error({
            title: '请先输入审定基金'
          })
          return
        }
        this.$jsonPost(`/assets/fund_month/next`, param).then(data => {
          this.toNextChecked(data)
        })
      },
      onPass() {
        let param = {
          id: this.id,
          isAudit: true,
          auditFundAmount: this.$refs.shopInfo.form.waitAuditFundNumber,
          auditRemark: this.$refs.shopInfo.form.auditRemark,
          query: {
            ...this.checkQuery
          }
        }
        if (param.auditFundAmount === null || param.auditFundAmount === '' || param.auditFundAmount === undefined) {
          this.$Notice.error({
            title: '请先输入审定基金'
          })
          return
        }
        this.$Modal.confirm({
          title: '提醒',
          content: '确定审核通过？',
          onOk: () => {
            this.$jsonPost(`/assets/fund_month/audit`, param).then(data => {
              this.$Notice.success({
                title: '审核通过'
              })
              this.toNextChecked(data)
            })
          }
        })
      },
      toNextChecked (data) {
        if (data) {
          this.$router.replace({
            name: 'welfare/fundcheck/info',
            query: {
              id: data,
              from: 'check'
            }
          })
          this.tab = 'tab1'
          this.id = data
          this.isCheck = true
          this.getDetail()
        } else {
          setTimeout(() => {
            this.$router.replace('/welfare/fundcheck/list')
          }, 200)
        }
      }
    }
  };
</script>
